package leetcode;

import java.util.Arrays;

/**
 * @Classname FindContentChildren_0455
 * @Author happytaohaha
 * @Date 2020/3/24
 * @Description 分发饼干 O(NlogN)
 */
public class FindContentChildren_0455 {
    public static int findContentChildren(int[] g, int[] s) {
        Arrays.sort(g);
        Arrays.sort(s);
        int len = s.length;
        int leng = g.length;
        if(leng<1) {return 0;}
        int j = 0;
        for (int i = 0; i < len; i++) {
            if( j < leng && s[i] >= g[j]){
                j++;
            }
        }
        return j;
    }

    public static void main(String[] args) {
        System.out.println(findContentChildren(new  int[]{1,2},new int[]{1,2,3}));
    }
}
